package com.cxx.rabbit.controller;

import com.cxx.rabbit.service.OrderService;
import com.cxx.rabbit.domain.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class PayController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/pay/{orderNo}")
    public String payOrder(
            @PathVariable("orderNo") String orderNo
    ) {

        Order order = new Order();
        order.setOrderNo(orderNo);

        boolean b = orderService.payOrder(order);
        if(b) {
            return "redirect:/page/pay_success/" + orderNo;
        }else{
            return "redirect:/order/list/"+orderService.getByOrderNo(orderNo).getUserId();
        }
    }

}
